package com.lzh.chatnote.user.service.adapter;

import com.lzh.chatnote.user.domain.entity.User;
import com.lzh.chatnote.user.domain.entity.UserFriend;
import com.lzh.chatnote.user.domain.vo.response.user.UserFriendResp;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class UserFriendAdapter {

    public static List<UserFriendResp> buildUserFriend(List<UserFriend> userFriendList,List<User> userList) {
        Map<Long, Integer> userOnlineMap = userList.stream().collect(Collectors.toMap(User::getId, User::getActiveStatus));
        return userFriendList.stream()
                .map(item ->
                        UserFriendResp.builder()
                                .uid(item.getFriendId())
                                .activeStatus(userOnlineMap.get(item.getFriendId()))
                        .build())
                .collect(Collectors.toList());
    }
}
